//filter.js
const appData = getApp();

function identityFilter(pageObj) {
  if (pageObj.onShow) {
    let _onShow = pageObj.onShow;
    pageObj.onShow = function() {
      //获取页面实例，防止this劫持
      let currentInstance = getPageInstance();
      appData.globalData.route = currentInstance.route
      //改动点
      if (appData.isNeedLogin()) {
        wx.showToast({
          title: '请先登录',
          icon: 'none',
          complete: (ev) => {
            setTimeout(function() {
              //跳转到登录页
              wx.navigateTo({
                url: "/pages/common/login/login"
              });
            }, 1500)

          }
        })

      } else {
        _onShow.call(currentInstance);
      }

    }
  }
  return pageObj;
}

function getPageInstance() {
  var pages = getCurrentPages();
  return pages[pages.length - 1];
}

exports.identityFilter = identityFilter;